package com.meepo.basic.router

import android.annotation.SuppressLint
import android.content.Context
import androidx.fragment.app.Fragment
import com.meepo.basic.components.listfragment.ListFragmentParams
import com.xiaojinzi.component.impl.*

@SuppressLint("CheckResult")
object RouterManager {
    object UserModule {
        private const val Host = "user"
        const val UserInfoEdit_Path = "$Host/userInfoEdit"
        const val UserListFragment_Path = "$Host.userListFragment"
        const val UserProfile_Path = "$Host/profile"

        fun routeToUserInfoEdit(context: Context) {
            RxRouter.with(context).hostAndPath(UserInfoEdit_Path)
                .navigate()
        }

        fun routeToUserListFragment(
            relationType: String = "",
            keyword: String = "",
            followUserId: String = "",
            listFragmentParams: ListFragmentParams = ListFragmentParams()
        ): Fragment {


            return RxRouter.with(UserListFragment_Path)
                .putString("relationType", relationType)
                .putString("keyword", keyword)
                .putString("followUserId", followUserId)
                .putSerializable("listFragmentParams", listFragmentParams)
                .navigate()!!
        }

        fun routeToUserProfile(context: Context, userId: String?) {
            userId?.let {
//                val path = if (Store.Func.isSelf(it)) UserProfileSelf_Path else UserProfile_Path
                RxRouter.with(context).hostAndPath(UserProfile_Path).query("userId", userId).navigate()
            }
        }
    }

    object FeedModule {
        private const val Host = "feed"
        const val FeedEssayPublish_Path = "$Host/feedEssayPublish"
        const val FeedAttitudeUserList_Path = "$Host/attitudeUserList"
        const val FeedHistory_Path = "$Host/feedHistory"
        const val ActionListFragment_Path = "$Host/actionListFragment"
        const val TopicListFragment_Path = "$Host/topicListFragment"
        const val EssayListFragment_Path = "$Host/essayListFragment"
        const val FeedMessageHistory_Path = "$Host/feedMessageHistory"
        const val FeedSearch_Path = "$Host/feedSearch"
        const val FeedTopicListSimple_Path = "$Host/topicListSimple"
        const val FeedTopicDetail_Path = "$Host/topicDetail"
        const val FeedComment_Path = "$Host/comment"
        const val CommentReplyListFragment_Path = "$Host/commentReplyListFragment"
        const val CommentListFragment_Path = "$Host/commentListFragment"
        const val FeedCommentReply_Path = "$Host/commentReply"

        fun routeToEssayPublish(context: Context) {
            RxRouter.with(context).hostAndPath(FeedEssayPublish_Path)
                .navigate()
        }

        fun routeToAttitudeUserList(context: Context, itemId: String) {
            RxRouter.with(context).hostAndPath(FeedAttitudeUserList_Path)
                .putString("itemId", itemId)
                .navigate()
        }

        fun routeToHistory(context: Context, index: Int = 0) {
            RxRouter.with(context).hostAndPath(FeedHistory_Path)
                .putInt("index", index)
                .navigate()
        }

        fun routeToActionList(
            itemType: String = "",
            actionType: String = "",
            authorUserId: String = "",
            targetUserId: String = "",
            listFragmentParams: ListFragmentParams? = null

        ): Fragment {
            return RxRouter.with(ActionListFragment_Path)
                .putString("itemType", itemType)
                .putString("actionType", actionType)
                .putString("authorUserId", authorUserId)
                .putString("targetUserId", targetUserId)
                .putSerializable("listFragmentParams", listFragmentParams)
                .navigate()!!
        }

        fun routeToTopicList(
            keyword: String = "",
            authorId: String = "",
            simple: Boolean = false,
            joinedByUserId: String = "",
            listFragmentParams: ListFragmentParams? = null
        ): Fragment {

            return RxRouter.with(TopicListFragment_Path)
                .putString("keyword", keyword)
                .putString("authorId", authorId)
                .putBoolean("simple", simple)
                .putString("joinedByUserId", joinedByUserId)
                .putSerializable("listFragmentParams", listFragmentParams)
                .navigate()!!
        }

        fun routeToCommentReplyList(
            itemId: String = "",
            mainCommentId: String = "",
            atUserId: String = "",
            authorId: String = "",
            forDisplay: Boolean = false,
            listFragmentParams: ListFragmentParams? = null
        ): Fragment {

            return RxRouter.with(CommentReplyListFragment_Path)
                .putString("itemId", itemId)
                .putString("mainCommentId", mainCommentId)
                .putString("atUserId", atUserId)
                .putString("authorId", authorId)
                .putBoolean("forDisplay", forDisplay)
                .putSerializable("listFragmentParams", listFragmentParams)
                .navigate()!!
        }

        fun routeToCommentList(
            itemId: String = "",
            mainCommentId: String = "",
            atUserId: String = "",
            authorId: String = "",
            forDisplay: Boolean = false,
            listFragmentParams: ListFragmentParams? = null
        ): Fragment {

            return RxRouter.with(CommentListFragment_Path)
                .putString("itemId", itemId)
                .putString("mainCommentId", mainCommentId)
                .putString("atUserId", atUserId)
                .putString("authorId", authorId)
                .putBoolean("forDisplay", forDisplay)
                .putSerializable("listFragmentParams", listFragmentParams)
                .navigate()!!
        }


        fun routeToFeedList(
            category: String = "",
            topicId: String = "",
            keyword: String = "",
            authorId: String = "",
            action: String = "",
            hideTopicView: Boolean = false,
            listFragmentParams: ListFragmentParams? = null
        ): Fragment {

            return RxRouter.with(EssayListFragment_Path)
                .putString("category", category)
                .putString("topicId", topicId)
                .putString("keyword", keyword)
                .putString("authorId", authorId)
                .putString("action", action)
                .putBoolean("hideTopicView", hideTopicView)
                .putSerializable("listFragmentParams", listFragmentParams)
                .navigate()!!
        }

        fun routeToMessage(context: Context, tabIndex: Int) {
            RxRouter.with(context).hostAndPath(FeedMessageHistory_Path)
                .query("tabIndex", tabIndex)
                .navigate()
        }

        fun routeToSearch(context: Context) {
            RxRouter.with(context).hostAndPath(FeedSearch_Path)
                .navigate()
        }

        fun routeToTopicListSimple(context: Context) {
            RxRouter.with(context).hostAndPath(FeedTopicListSimple_Path)
                .navigate()
        }

        fun routeToFeedTopicDetail(context: Context, topicId: String) {
            RxRouter.with(context).hostAndPath(FeedTopicDetail_Path)
                .query("topicId", topicId)
                .navigate()

        }

        fun routeToFeedComment(context: Context, itemId: String, hideTopicView: Boolean = false) {
            RxRouter.with(context).hostAndPath(FeedComment_Path)
                .query("itemId", itemId)
                .query("hideTopicView", hideTopicView)
                .navigate()

        }

        fun routeToFeedCommentReply(context: Context, commentId: String) {
            RxRouter.with(context).hostAndPath(FeedCommentReply_Path)
                .query("commentId", commentId)
//                .query("itemId", itemId)
                .navigate()
        }


    }


}